------------------------------
-- 2维向量类
------------------------------
local M = {}

local metaTable = {
	__mul = function(a, b)
		if not a or not b then
			print("argument could not be nil")
		end
		local x, y
		if type(a) == "number" then
			x = b.x*a
			y = b.y*a
		else
			x = a.x*b
			y = a.y*b
		end

		return M:new(x, y)
	end,
	__add = function(a, b)
		local x = a.x + b.x
		local y = a.y + b.y

		return M:new(x, y)
	end
}

function M:new(x, y)
	if not x or not y then
		print("vec2 参数错误")
		return
	end

	local newVec2 = {
		x = x,
		y = y
	}

	setmetatable(newVec2, metaTable)

	return newVec2
end

local function testFunc()
	local vecTest = M:new(1, 2)

	local newVec = 2*vecTest

	print(vecTest.x, vecTest.y)
	print(newVec.x, newVec.y)
end

return M